/**
 * Created by 李柏霖
 * 2020/10/13 10:18
 */

package com.lbl.Controller;

import com.lbl.Utils.Db;
import com.lbl.domain.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class PersonController {

    @RequestMapping("list.action")
    public ModelAndView findAll(){
        //1获取
        //2转发到页面
        //3在页面上进行forEach循环
        List<Person> list = Db.findAll();
        ModelAndView mv = new ModelAndView();
        mv.addObject("list",list);
        mv.setViewName("list");
        return mv;
    }

    @RequestMapping("login.action")
    public ModelAndView login(String username,String password){
        //1获取
        //2转发到页面
        //3在页面上进行forEach循环
        System.out.println(username);
        System.out.println(password);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("main");
        return mv;
    }
    @RequestMapping("register.action")
    public ModelAndView register(Person person){
        //1获取
        //2转发到页面
        //3在页面上进行forEach循环
        System.out.println(person.getUsername());
        System.out.println(person.getPassword());
        System.out.println(person.getBirthDay().getYear());
        System.out.println(person.getBirthDay().getMonth());
        System.out.println(person.getBirthDay().getDay());
        List<Person> list = Db.add(person);
        ModelAndView mv = new ModelAndView();
        mv.addObject("list",list);
        mv.setViewName("personList");
        return mv;
    }


}
